<template>
  <div class="mod-user">
    <el-button plain disabled>提现管理</el-button>
    <el-button plain @click="WithdrawalRecord">提现记录</el-button>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <!-- <el-form-item>
          <div class="balance-searchMoney">
            状态

            <el-select v-model="value2"  @change="status" filterable placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </div>
        </el-form-item> -->
        <el-form-item>
          <div class="balance-searchMoney">
            提现申请时间
            <el-date-picker v-model="value" type="daterange" value-format="yyyy-MM-dd HH:mm:ss" class="input" start-placeholder="开始日期" :clearable='false' end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            提现申请单位
            <el-select v-model="value1" filterable placeholder="请选择">
              <el-option v-for="item in city" :key="item.legalAccountCode" :label="item.legalCompanyName" :value="item.legalAccountCode">
              </el-option>
            </el-select>
          </div>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="primary" @click="demand">查询</el-button>
        <el-button type="primary" @click="empty">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color" style="width: 100%;">
      <template slot="empty">
        <img class="machine" src="../../assets/img/machine.svg" alt="" />
        <div style="font-size: 14px; text-align: center">暂无数据</div>
      </template>
      <el-table-column prop="applyNo" header-align="center" align="center" label="提现申请单号" width="120">
      </el-table-column>
      <el-table-column prop="applyTime" header-align="center" align="center" label="提现申请时间" width="120">
      </el-table-column>
      <el-table-column prop="applyFee" header-align="center" align="center" label="结算金额(元)" width="120">
        <template slot-scope="scope">
          <div @click="addMoney(scope.row.cycleNos)" class="cycleNos">
            {{ scope.row.applyFee| MoneyFormat }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="cycleNos" header-align="center" align="center" label="关联结算单号" width="150" :render-header="renderHeader">
        <template slot-scope="scope">
          <div v-for="(title, index) in scope.row.cycleNos" :key="index" class="cycleNos">
            <div @click="addOrUpdateHandle(title)">{{ title }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="legalCompanyName" header-align="center" align="center" label="提现申请单位" width="120">
      </el-table-column>
      <el-table-column prop="accountNickname" header-align="center" align="center" label="提现申请人" width="120">
      </el-table-column>
      <el-table-column prop="approverCompanyName" header-align="center" align="center" label="审批单位" width="120">
      </el-table-column>
      <el-table-column prop="status" header-align="center" align="center" label="提现状态" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.applyStatus === 0" class="orangeMoney">
            提现审批中
          </div>
          <div v-if="scope.row.applyStatus === 1" class="greenMoney">
            完成提现
          </div>
          <div v-if="scope.row.applyStatus === 2" class="grayMoney">
            提现审批未通过
          </div>
        </template>
      </el-table-column>

      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.applyStatus == 0" type="text" size="small" @click="open(scope.row)">同意提现</el-button>
          <el-button v-if="scope.row.applyStatus == 0" type="text" size="small" @click="openNo(scope.row)">不同意提现</el-button>
          <el-button v-if="scope.row.applyStatus == 1" @click="see(scope.row)" type="text" size="small">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 弹框 -->
    <el-dialog title="请输入不同意提现理由" :visible.sync="dialogVisible" width="30%">
      <textarea maxlength="200" name="" id="" v-model="rejectReason" class="textArea" cols="30" rows="10"></textarea>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="moneyNo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        userName: "",
      },
      options: [
        {
          value: "0",
          label: "审核中",
        },
        {
          value: "1",
          label: "审核通过",
        },
      ],
      len: '',
      cycleNo: "",
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      startApplyTime: "",
      endApplyTime: "",
      value1: "",
      value: "",
      value2: "",
      city: [],
      dialogVisible: false,
      rejectReason: "",
    };
  },
  activated () {
    this.getDataList();
    this.cityList();
  },
  methods: {
    // 表格头部提示事件
    renderHeader (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "本条提现是哪个结算账单，点击可查看结算账单和账单明",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "本条提现是哪个结算账单，点击可查看结算账单和账单明",
          }
        ),
      ]);
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/withdrawApply/list"),
        method: "get",
        params: this.$http.adornParams({
          applyStatus: this.applyStatus,
          startApplyTime: this.startApplyTime,
          endApplyTime: this.endApplyTime,
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/withdrawApply/list"),
        method: "get",
        params: this.$http.adornParams({
          applyStatus: this.applyStatus,
          startApplyTime: this.value[0] || '',
          endApplyTime: this.value[1] || '',
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.value1,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/withdrawApply/list"),
        method: "get",
        params: this.$http.adornParams({
          applyStatus: this.applyStatus,
          startApplyTime: this.value[0] || '',
          endApplyTime: this.value[1] || '',
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.value1,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 查看单号
    addOrUpdateHandle (cycleNo) {
      this.$router.push({
        name: `totalFinance-settlementList`,
        query: {
          cycleNo: cycleNo,
        },
      });
    },
    // 全部单号
    addMoney (cycleNos) {
      this.$router.push({
        name: `totalFinance-settlementDetail`,
        query: {
          cycleNos: cycleNos,
        },
      });
    },
    // 查看相亲
    see (e) {
      console.log(e.applyNo);
      this.$router.push({
        name: `totalFinance-WithdrawalRecord`,
        query: {
          applyNo: e.applyNo,
        },
      });
    },
    // 获取数据列表
    cityList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/legalCompany/getByCurrentFinanceCode"
        ),
        method: "get",
        params: this.$http.adornParams({}),
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data);
          this.city = data.data;
        } else {
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    // 弹框
    open (e) {
      this.applyNo = e.applyNo;
      this.$confirm(
        "本次提现金额为" +
        e.applyFee.toFixed(2) +
        "元，提现对象为" +
        e.legalCompanyName +
        "。请再次确认结算信息是否正确。",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        }
      )
        .then(() => {
          this.$http({
            url: this.$http.adornUrl(
              "cassadmin/v1/withdrawApply/approveWithdraw"
            ),
            method: "post",
            data: this.$http.adornData({
              applyNo: this.applyNo,
            }),
          }).then(({ data }) => {
            if (data.success == 1) {
              this.$message({
                type: "success",
                message: "提现成功!",
              });
              this.getDataList();
            } else {
              this.$message.error(data.errorMsg);
            }
            this.dataListLoading = false;
          });
        })
        .catch(() => { });
    },
    // 不同意提现
    openNo (e) {
      this.applyNo = e.applyNo;
      this.dialogVisible = true;
    },
    // 不同意原因
    moneyNo () {
      if (this.rejectReason == "") {
        this.$message.error("请输入不同意原因");
        return;
      }
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/v1/withdrawApply/rejectWithdrawDTO"
        ),
        method: "post",
        data: this.$http.adornData({
          applyNo: this.applyNo,
          rejectReason: this.rejectReason,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.dialogVisible = false;
          this.getDataList();
        } else {
          this.$message.error(data.errorMsg);
        }
      });
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/withdrawApply/list"),
        method: "get",
        params: this.$http.adornParams({
          applyStatus: this.applyStatus,
          startApplyTime: this.value[0] || '',
          endApplyTime: this.value[1] || '',
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.value1,
        }),
      }).then(({ data }) => {
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    //清空
    empty () {
      this.value = ''
      this.value1 = ''
      this.getDataList()
    },
    // 状态
    status (e) {
      this.pageIndex = 1;
      this.applyStatus = e;
      this.getDataList();
    },
    // 提现记录
    WithdrawalRecord () {
      this.$router.push({
        name: `totalFinance-WithdrawalRecord`,
      });
    },
  },
};
</script>
<style scoped>
.input {
  flex: 1;
  margin-left: 5px;
}
.gary {
  color: #ccc;
}
</style>
